package com.shf.lease.web.admin.controller.apartment;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shf.lease.entity.FacilityInfo;
import com.shf.lease.enums.ItemType;
import com.shf.lease.result.Result;
import com.shf.lease.web.admin.service.FacilityInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 叶枫
 * @date 2024/7/4.
 */

@Tag(name = "配套管理")
@RestController
@RequestMapping("/admin/facility")
public class FacilityController {

    @Resource
    private FacilityInfoService facilityInfoService;
    @Operation(summary = "查询配套列表")
    @GetMapping("/list")
    public Result<List<FacilityInfo>> getFacilityList(@RequestParam(required = false)ItemType type) {
        //构造查询条件
        LambdaQueryWrapper<FacilityInfo> qu = new LambdaQueryWrapper<>();
        qu.eq(type !=null,FacilityInfo::getType,type);
        return Result.ok(facilityInfoService.list(qu));

    }
    @Operation(summary = "新增or更新配套")
    @RequestMapping(value = "/saveOrUpdate",method = {RequestMethod.POST,RequestMethod.PUT})
    public Result<?> saveOrUpdateFacility(@RequestBody FacilityInfo facilityInfo) {
        return facilityInfoService.saveOrUpdate(facilityInfo) ? Result.ok() : Result.fail();
    }

}
